package com.and.xmppsdk.fragment.panel;



import com.and.xmppsdk.R;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

/**
 * 选项面板，从下面滑上来
 * 
 */
public class OptionPanel extends DialogFragment {
	
	public static final String TAG = OptionPanel.class.getName();
	
	
	protected ButtonTextCallBackable mFirstCallback;
	
	protected ButtonTextCallBackable mMiddleCallback;
	
	protected ButtonTextCallBackable mLastCallback;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setStyle(DialogFragment.STYLE_NO_FRAME, R.style.Theme_Option);
	}

	/**
	 * 该方法将不再使用
	 */
	@Override
	@Deprecated
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		return super.onCreateDialog(savedInstanceState);
	}
	
	/**
	 * 该方法将不再使用
	 */
	@Override
	@Deprecated
	public Dialog getDialog() {
		return super.getDialog();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	public final View wrapToPanel(View view) {
		LinearLayout frameLayout = new LinearLayout(getActivity());
		frameLayout.setLayoutParams(new LinearLayout.LayoutParams(
				android.widget.LinearLayout.LayoutParams.FILL_PARENT,
				android.widget.LinearLayout.LayoutParams.FILL_PARENT));
		frameLayout.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
		frameLayout.setOrientation(LinearLayout.VERTICAL);
		
		LinearLayout linearLayout = new LinearLayout(getActivity());
		linearLayout.setLayoutParams(new LinearLayout.LayoutParams(
				android.widget.LinearLayout.LayoutParams.FILL_PARENT,
				android.widget.LinearLayout.LayoutParams.WRAP_CONTENT));
		linearLayout.setOrientation(LinearLayout.VERTICAL);
		linearLayout.setBackgroundResource(R.drawable.option_panel_bg);
		linearLayout.addView(view);
		frameLayout.addView(linearLayout);
		return frameLayout;
	}
	
	/**
	 * 按钮上的文字设置
	 */
	public interface ButtonTextCallBackable {
		void onCall(Button button);
	}
	
	/**
	 * 设置回调
	 * @param callback
	 */
	public void setFirstButtonTextCallBackable(ButtonTextCallBackable callback) {
		this.mFirstCallback = callback;
	}
	
	/**
	 * 设置回调
	 * @param callback
	 */
	public void setMiddleButtonTextCallBackable(ButtonTextCallBackable callback) {
		this.mMiddleCallback = callback;
	}
	
	/**
	 * 设置回调
	 * @param callback
	 */
	public void setLastButtonTextCallBackable(ButtonTextCallBackable callback) {
		this.mLastCallback = callback;
	}
	
}
